package gdconf

import (
	"server_cluster/common/logger"
)

// 爬塔配置表

type TowerConfig struct {
	TowerId       int32 `csv:"Id" gorm:"primary_key;autoIncrement:false"` // 爬塔id
	Area          int32 `csv:"Area,omitempty"`                            // 区域
	Level         int32 `csv:"Level,omitempty"`                           // 关卡
	BattleGroupId int32 `csv:"BattleGroup,omitempty"`                     // 战斗组id
	ActivityId    int32 `csv:"ActivityId,omitempty"`
}

func (t *TowerConfig) TableName() string {
	return "config_tower"
}

func (g *GameDataConfig) saveTowerConfig() {
	saveTableToDb[TowerConfig](g.Db, readTable[TowerConfig](g.CsvPathPrefix+"Tower.csv"))
}

func (g *GameDataConfig) loadTowerConfig() {
	g.GameDataMaps.TowerConfigMap = make(map[int32]*TowerConfig)
	for _, towerConfig := range loadTableFromDb[TowerConfig](g.Db) {
		g.GameDataMaps.TowerConfigMap[towerConfig.TowerId] = towerConfig
	}
	logger.Info("TowerConfig Count: %v", len(g.GameDataMaps.TowerConfigMap))
}

func GetTowerConfig(towerId int32) *TowerConfig {
	value, exist := CONF.GameDataMaps.TowerConfigMap[towerId]
	if !exist {
		logger.Error("[ConfigNotFound] TowerConfig, towerId: %v", towerId)
		return nil
	}
	return value
}

func GetTowerConfigMap() map[int32]*TowerConfig {
	return CONF.GameDataMaps.TowerConfigMap
}
